package com.lyc.day1102.demo7;


import java.util.concurrent.*;

/**
 * @author ：Xiaochen
 * @date ：Created in 2022/11/2 19:20
 * @description：
 * @modified By：
 * @version:
 */
public class TestExecutors {
    public static void main(String[] args) {
        //创建单一线程池---池子中且仅有一个线程对象
        //ExecutorService executorService = Executors.newSingleThreadExecutor();

        //创建固定长度的线程池----池子中线程的数量是固定的。---里面预先会创建n个线程对象。
//        ExecutorService executorService = Executors.newFixedThreadPool(3);

        //创建可变长度的线程池----根据任务的个数创建线程对象
//        ExecutorService executorService = Executors.newCachedThreadPool();

        //创建延迟线程池
//        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(5);


        ThreadPoolExecutor executorService=new ThreadPoolExecutor(2,5,2000,TimeUnit.SECONDS,new LinkedBlockingDeque(3));

        //往线程池中提交任务
        for (int i = 0; i < 5; i++) {
            final int a=i;
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName()+"-------"+a);
                }
            });




//            scheduledExecutorService.schedule(new Runnable() {
//                @Override
//                public void run() {
//                    System.out.println(Thread.currentThread().getName()+"-------"+a);
//                }
//            },20, TimeUnit.SECONDS);



//            executorService.submit(new Runnable() {
//                @Override
//                public void run() {
//                    System.out.println(Thread.currentThread().getName()+"-------"+a);
//                }
//            });
        }
    }
}